<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 14-6-23
 * Time: 下午6:01
 */

namespace Common\Org\Attach;


class Attach {
    static private $host;
    static private $interface_url;

    static private function generateApiKey()
    {
        return md5(time()).md5(uniqid()).md5(time().uniqid()).md5(mt_rand(1,100000));
    }

    static function get_attach($data)
    {
        if(empty($data)) return NULL;

        self::$host = 'http://u.'.DOMAIN_SUFFIX;
        self::$interface_url = 'http://u.'.DOMAIN_SUFFIX.'/attach.php';
        $parameter['akey'] = C('UPLOAD_SECRET');
        $parameter['skey'] = self::generateApiKey();
        $secret = get_secret($parameter['akey'],$parameter['skey']);
        static $client;
        if(!$client) $client = new \Common\Org\Sms\HttpClient();

        $parameter['data'] = json_encode($data);
        $key = params_deal(self::$host,$parameter);
        $parameter['sig'] = get_signature($key,$secret);

        $ret = $client->post(self::$interface_url,$parameter);
        $ret = json_decode($ret,true);

        return $ret;
    }
} 